Skip to content

Week1: API + 로컬 개발환경 + 기본 Docker화#1

Open
hjklo0220 wants to merge 17 commits intomainfrom
week1
Open

Week1: API + 로컬 개발환경 + 기본 Docker화#1
hjklo0220 wants to merge 17 commits intomainfrom
week1

Conversation

@hjklo0220
Copy link
Copy Markdown
Collaborator

@hjklo0220 hjklo0220 commented Apr 4, 2026

작업 내용

  • node Fastify 기반 API 서버 기본 구조 (health/ 엔드포인트)
  • PostgreSQL 연결 플러그인
  • packages/shared 패키지 — pino 로거, 공유 타입(HealthResponse)
  • Dockerfile - Multi-stage builds
    • deps/builder/runner 분리로 devDependencies 제거
    • 빌드 전략 비교 분석 (docs/docker.md)
  • docker-compose.yml 작성 (api + postgres 로컬 환경)
    • migrate 컨테이너 추가 (depends_on의 condition활용) 분석 (docs/docker-compose.md)
  • postgres 컨테이너 연결 및 환경변수 구성
  • items crud API 구현

hjklo0220 and others added 17 commits April 4, 2026 02:22
pino 로거와 공유 타입(HealthResponse)을 shared 패키지로 분리.
tsconfig.json 추가로 독립 빌드 가능하도록 구성.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fastify 기본 logger 대신 shared pino 로거를 주입하고,
health 엔드포인트 응답에 HealthResponse 타입을 적용.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
deps 스테이지를 추가해 production node_modules(--omit=dev)와
빌드용 node_modules를 분리. shared도 dist만 복사하도록 개선.
node_modules 48.6MB → 20.1MB, 이미지 212MB → 147MB.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3-stage 구조 설명, 실측 이미지 크기 비교(naive/optimized/prod),
npm workspaces 심링크 동작 원리, packages/shared 사전 조건 추가.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
api/db 로컬 개발환경 구성. service_healthy로 DB 준비 후 api 시작,
healthcheck, env_file 분리. .env.example로 필요 변수 문서화.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
domain/item.ts에 순수 계약(타입+인터페이스) 분리.
AppError 중앙화, pgItemRepository는 domain 인터페이스 구현체로 분리.
service는 domain 인터페이스만 의존해 DB 구현체와 결합 없음.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
POST/GET/PUT/DELETE /items 구현.
Fastify JSON schema로 name(minLength:1, maxLength:255) validation,
PUT 빈 body 거절(minProperties:1). schema는 schemas/ 디렉토리로 분리.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
id, name, description, view_count, created_at, updated_at 컬럼.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
app.ts에 buildApp 팩토리 분리(테스트 재사용 목적).
index.ts는 listen만 담당. app.after()에서 pg Pool 꺼내 repo/service 조립.
shared pino logger를 loggerInstance로 주입(타입 단언으로 호환).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Vitest + app.inject() 기반 통합 테스트 20케이스.
POST/GET/PUT/DELETE 각 ECP 동치 클래스 + BVA 경계값(name 0/1/255/256자).
beforeEach/afterEach로 테스트 격리, TRUNCATE로 DB 상태 초기화.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
레이어 구조를 domain/repositories/services/routes로 업데이트.
의존성 방향, 에러 처리 방식 추가.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add node-pg-migrate as runtime dependency
- Add migrate script to package.json
- Convert 001_create_items.sql to node-pg-migrate JS format
- Copy migrations/ in Dockerfile runner stage for migrate container
- Replace postgres:16-alpine + psql with api image + node-pg-migrate in docker-compose
- Add service_completed_successfully condition so api starts after migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Compare entrypoint script vs separate container approach
- Document depends_on condition types and startup order
- Include measured metrics (migrate time, image sizes)
- Note K8s Job/InitContainer mapping for future migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
26 Security Hotspots

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant